package org.idea.spring.resource;

import org.springframework.core.io.*;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author linhao
 * @Date created in 7:38 下午 2021/5/23
 */
public class ResourceLoaderDemo {

    public static void main(String[] args) throws IOException {
        ResourceLoader loader = new DefaultResourceLoader();
        Resource resource = loader.getResource("http://www.baidu.com");
        InputStream inputStream = resource.getInputStream();
        byte[] bytes = new byte[1024];
        String result = new String();
        while (inputStream.read(bytes)!=-1){
            result = result + new String(bytes);
        }
        System.out.println(result);
        System.out.println(resource instanceof UrlResource);
        Resource textResource = loader.getResource("classpath:test.txt");
        System.out.println(textResource instanceof ClassPathResource);
    }
}
